package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.CheckItemDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

//检查项服务
@Service(interfaceClass = CheckItemService.class)
@Transactional
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
     private CheckItemDao checkItemDao;

     //添加检查项
    @Override
    public void add(CheckItem checkItem) {
        checkItemDao.add(checkItem);
    }

    //分页查询
    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        //        mybatis 分页助手
        PageHelper.startPage(currentPage,pageSize);
        Page<CheckItem> page = checkItemDao.selectByCondition(queryPageBean.getQueryString());
        return new PageResult(page.getTotal(),page.getResult());
    }

    //删除检查项
    @Override
    public void del(Integer id)  {
        //判断是否与检查组关联
        long num = checkItemDao.findCountByCheckItemId(id);
        if (num>0){
             new RuntimeException();
        }
        checkItemDao.del(id);
    }
    //回写检查项查询
    @Override
    public CheckItem FindAll(Integer id) {
        CheckItem checkItem = checkItemDao.FindAll(id);
        return checkItem;
    }
    //编辑检查项
    @Override
    public void edit(CheckItem checkItem) {
        checkItemDao.edit(checkItem);
    }

    //查询所有检查项数据
    @Override
    public List<CheckItem> findallitem() {
        List<CheckItem> itemList=checkItemDao.findallitem();
        return itemList;
    }
}
